//弹球
export class Ball {
  x = 100;
  y = 250;
  width = 50;
  height = 50;
  speedX = 3;
  speedY = 3;
  fired = false; //发射开关
  lastBump = false; //上一次是否发生相撞
  constructor(private canvasWidth: number, private canvasHeight: number) {}
  move() {
    if (!this.fired) return;
    if (this.x < 0 || this.x + this.width > this.canvasWidth) this.reboundX();
    if (this.y < 0 || this.y + this.height > this.canvasHeight) this.reboundY();
    this.x += this.speedX;
    this.y += this.speedY;
  }
  suspend() {
    this.fired = !this.fired;
  }
  reboundY() {
    this.speedY *= -1;
  }
  reboundX() {
    this.speedX *= -1;
  }
}